﻿using System;
using Microsoft.Xna.Framework;
using PersianCore;
using PersianCore.Meshes;

namespace PersianEngine
{
    class Knifes
    {
        #region Constructor

        public Mesh mesh { get; set; }
        Vector2[] KnifePosition;
        Vector2[] LastKnifePos;

        #endregion

        #region Load

        public Knifes()
        {
            this.KnifePosition = new Vector2[2];
            this.LastKnifePos = new Vector2[2];
        }

        public void Load(Mesh mesh)
        {
            this.mesh = mesh;
        }

        #endregion

        #region Update

        public void Update(Vector2 RightHand)
        {
            if (this.mesh.ID.StartsWith("RKni"))//Right Knife
            {
                LastKnifePos[0] = KnifePosition[0];
                KnifePosition[0] = RightHand;

                KnifePosition[0].X /= (CoreShared.DisplayWidth / 10.0f);
                KnifePosition[0].Y /= (CoreShared.DisplayHeight / 6.5f);
                this.mesh.Position = new Vector3(-45, 14.5f - KnifePosition[0].Y, KnifePosition[0].X - 8.0f);
                this.mesh.EnablePhysic = false;

                float Rotate =  (float)(Math.Atan((this.mesh.Position.Y - LastKnifePos[0].Y) / (this.mesh.Position.X - LastKnifePos[0].X)));
                this.mesh.Rotation = new Vector3(-0.7f + Rotate, MathHelper.ToRadians(90) + 2 * Rotate, -2 * Rotate);
            }
            //else if (this.mesh.ID.StartsWith("LKni"))//Left Knife
            //{
            //    LastKnifePos = KnifePosition;

            //    KnifePosition[1].X /= (CoreShared.DisplayWidth / 10.0f);
            //    KnifePosition[1].Y /= (CoreShared.DisplayHeight / 6.5f);
            //    iter.Position = new Vector3(-45, 14.5f - KnifePosition[1].Y, KnifePosition[1].X - 8.0f);
            //    iter.EnablePhysic = false;

            //    float Rotate = (float)(Math.Atan((iter.Position.Y - LastKnifePos[1].Y) / (iter.Position.X - LastKnifePos[1].X)));
            //    iter.Rotation = new Vector3(-1.0f + Rotate, MathHelper.ToRadians(-45) + 2 * Rotate, -10 * Rotate);
            //}
        }

        #endregion
    }
}
